<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.common.*"  %>
<%@ page import="com.qijia.travel.helper.*"  %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String detailId = request.getParameter("detailId");
EptManager touristManager = new EptManager();
TouristExpenditure detail = new TouristExpenditure();


boolean modify = false;
if(detailId!=null)modify = true;

if(modify){

Guide guide = (Guide)session.getAttribute(Constants.USER_KEY);
if(guide.getGuideType()==null||guide.getGuideType()!=1|| 79!=guide.getGuideId()){
out.println("<script>alert('你没有此权限，请联系管理员开通此权限!');window.close();window.parent.location.reload();</script>");
}
try{
   int ID = Integer.parseInt(detailId);
   detail = touristManager.getTouristExpenditureById(ID);
   if(detail==null){
      out.println("<script>alert('选择的支出项不存在');window.close();window.parent.location.reload();</script>");
   }
 }catch(NumberFormatException e){
   out.println("<script>alert('选择的支出项不存在');window.close();window.parent.location.reload();</script>");
   response.sendRedirect("tourist.jsp");
 }catch(AppErrorException ex){
   out.println("<script>alert('获取数据失败!');window.close();window.parent.location.reload();</script>");
}
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/displayLayer.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/calendar.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/popupdiv_shim.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/ajaxPopup.js"></script>
<style type="text/css">
<!--
body {
	margin:0;
	padding:10px 0;
	font-size:12px;
}
ul,li{
    list-style:none;
}
textarea{width:150px;font-size:12px;}
.ipt{width:150px;}
.ipt2{width:40px;}
.btn{border:#002d96 1px solid; padding:4px 4px 2px; font-size:12px; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#9DBCEA); cursor:hand; color:black;}
#wrapper{
	width:460px;
	height:420px;
	margin:0 auto;
	overflow:hidden;
}
#content{
    float:left;
	width:460px;
	height:auto;
	padding:10px 0;
}
#content ul{
	float:left;
	width:100%;
	height:auto;
}
#content li{
	float:left;
	width:100%;
	height:auto;
	line-height:30px;
}
#content span{
    float:left;
	display:block;
	width:100px;
	text-align:right;
}
-->
</style>
</head>

<body>
<div id="wrapper">
    <form method="post" action="">
    <div id="content">
	    <ul>
		    <li><span><font color="red">*</font>收支项名称：</span><input type="text" id="expenditureName" name="detail.expenditureName" class="ipt" value="<%=detail.getExpenditureName()==null?"":detail.getExpenditureName()%>" /></li>
			
			<li><span><font color="red">*</font>类型：</span>
			  <select name="detail.ioType" class="ipt">
			     <option value="1" <%=detail.getIoType()==null||detail.getIoType()==1?"selected":""%>>支出</option>
			     <option value="2" <%=detail.getIoType()!=null&&detail.getIoType()!=1?"selected":""%>>收入</option>
			  </select>
			</li>
			
			<li><span><font color="red">*</font>收支类型：</span><input type="text" id="expenditureType" name="detail.expenditureType" class="ipt" value="<%=detail.getExpenditureType()==null?"":detail.getExpenditureType()%>" /></li>
			<li><span><font color="red">*</font>经手人编号：</span><input type="text" id="guideId" name="detail.guideId" class="ipt" value="<%=detail.getGuideId()==null?"":detail.getGuideId()%>" onblur="setGuideName(this)"/></li>
			
			<li><span><font color="red">*</font>经手人姓名：</span><input type="text" id="guideName" name="guideName" class="ipt" value="<%=detail.getGuideName()==null?"":detail.getGuideName()%>" onblur="setGuideId(this)"/></li>
			<li><span><font color="red">*</font>金额：</span><input type="text" id="expenditureAmount" name="detail.expenditureAmount" class="ipt" value="<%=detail.getExpenditureAmount()==null?"":detail.getExpenditureAmount()%>"/></li>
			
			<li><span><font color="red">*</font>日期：</span>
                <input type="text" id="startImg" name="detail.expenditureDt" size="10" readonly="readonly" value="<%=detail.getExpenditureDate()==null?"":DateHelper.parseToString(detail.getExpenditureDate(),DateHelper.yyyyMMdd)%>" onclick="fPopCalendar(document.getElementById('startImg'),document.getElementById('startImg'));return false;" onkeydown="iniTxt_OnKeydown(event,this);" />
            </li>
			<li><span>说明：</span><input type="text" name="detail.expenditureDesc" class="ipt" value="<%=detail.getExpenditureDesc()==null?"":detail.getExpenditureDesc()%>"/></li>
			<% if(modify){%>
			<li style="padding:0 0 0 100px;">
			   <input type="hidden" name="detail.expenditureId" value="<%=detail.getExpenditureId()==null?"":detail.getExpenditureId()%>"/>
			   <input name="" type="button" class="btn" value="确定" onclick="updateDetail()"/>
			   <input name="" type="reset" class="btn" value="重置"/>
			</li>
		    <%}else{%>
		    <li style="padding:0 0 0 100px;">
		       <input name="" type="button" class="btn" value="确定" onclick="createDetail()"/>
		       <input name="" type="reset" class="btn" value="重置"/>   
		    </li>
		    <%}%>
		</ul>
	</div>
	</form>
</div>
<script src="<%=basePath%>dwr/interface/eptManager.js"></script>
<script src="<%=basePath%>dwr/interface/guideManager.js"></script>
<script src="<%=basePath%>dwr/engine.js"></script>
<script src="<%=basePath%>js/jquery.js"></script>
<script>
function setPk(){
  $("#touristGroupSn").attr("value","");
  ranHelper.getPk(function(data){
    $("#touristGroupSn").val(data);
  });
}
function setGuideName(inputObj){
 if($.trim(inputObj.value)=="")return;
  $("#guideName").attr("value","");
 guideManager.getGuideById(inputObj.value,function(data){
    if(data!=null&&data.guideName!=null){
       $("#guideName").val(data.guideName);
    }
 });
}
function setGuideId(inputObj){
 if($.trim(inputObj.value)=="")return;
  $("#guideId").attr("value","");
 guideManager.getGuideByName(inputObj.value,function(data){
    if(data!=null&&data.guideId!=null){
       $("#guideId").val(data.guideId);
    }
 });
}


<% if(modify){%>
 function updateDetail(){
   var data=new Object;
   $("input[name^=detail]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   
   $("select[name^=detail]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   
   eptManager.updateTouristExpenditure(data,function(e){
     alert("修改成功!");
     window.close();
     window.parent.location.reload();
   });
 }
<%}else{%>
 function createDetail(){
   var data=new Object;
   $("input[name^=detail]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   
   $("select[name^=detail]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   
   eptManager.createTouristExpenditure(data,function(e){
     alert("添加成功!");
     window.close();
     window.parent.location.reload();
   });
 }
 <%}%>
</script>
</body>
</html>
